Do not retry past formats when loading all formats for the first time #6902
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When opening an image, Pillow loops through the different possible formats.
Pillow/src/PIL/Image.py
Lines 3242 to 3244 in 0b53853
If I add a
print
statement to see which formats it checks,and then run
I get
The first set of formats are checked twice - BMP, DIB, GIF, JPEG, PPM and PNG.
This is because after the preinit formats fail to load the SPIDER image, Pillow initialises the rest of the formats, and then just checks all the formats again, even the preinit ones that already failed.
Pillow/src/PIL/Image.py
Lines 3268 to 3272 in 43bb035
So this PR excludes the already checked formats the second time.